name: Chroma Cluster Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
      - '**'
  workflow_dispatch:

jobs:
  test-python:
    strategy:
      matrix:
        python: ['3.8']
        platform: ['16core-64gb-ubuntu-latest']
        testfile: ["chromadb/test/db/test_system.py",
                   "chromadb/test/ingest/test_producer_consumer.py",
                   "chromadb/test/segment/distributed/test_memberlist_provider.py",
                   "chromadb/test/test_logservice.py"]
    runs-on: ${{ matrix.platform }}
    steps:
    - name: Checkout
      uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python }}
    - name: Install test dependencies
      run: python -m pip install -r requirements.txt && python -m pip install -r requirements_dev.txt
    - name: Install Tilt
      run: |
        TILT_VERSION="0.33.3"
        curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$TILT_VERSION/tilt.$TILT_VERSION.linux.x86_64.tar.gz | \
          tar -xzv -C /usr/local/bin tilt
    - name: Install ctlptlc
      run: |
        CTLPTL_VERSION="0.8.20"
        curl -fsSL https://github.com/tilt-dev/ctlptl/releases/download/v$CTLPTL_VERSION/ctlptl.$CTLPTL_VERSION.linux.x86_64.tar.gz | \
          tar -xzv -C /usr/local/bin ctlptl
    - name: Set up kind
      run: ctlptl create cluster kind --registry=ctlptl-registry
    - name: Start Tilt
      run: tilt ci
    - name: Test
      run: bin/cluster-test.sh bash -c 'python -m pytest "${{ matrix.testfile }}"'
  test-go:
    runs-on: '16core-64gb-ubuntu-latest'
    steps:
    - name: Checkout
      uses: actions/checkout@v3
    - name: Install Tilt
      run: |
        TILT_VERSION="0.33.3"
        curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$TILT_VERSION/tilt.$TILT_VERSION.linux.x86_64.tar.gz | \
          tar -xzv -C /usr/local/bin tilt
    - name: Install ctlptlc
      run: |
        CTLPTL_VERSION="0.8.20"
        curl -fsSL https://github.com/tilt-dev/ctlptl/releases/download/v$CTLPTL_VERSION/ctlptl.$CTLPTL_VERSION.linux.x86_64.tar.gz | \
          tar -xzv -C /usr/local/bin ctlptl
    - name: Set up kind
      run: ctlptl create cluster kind --registry=ctlptl-registry
    - name: Start Tilt
      run: tilt ci
    - name: Test
      run: bin/cluster-test.sh bash -c 'cd go && go test -timeout 30s -run ^TestNodeWatcher$ github.com/chroma/chroma-coordinator/internal/memberlist_manager'
